package com.wsc.springbootmultidevdemo.msg.routing;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wsc.springbootmultidevdemo.msg.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 路由模式
 */
public class Send {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        String EXCHANGE_NAME = "routing";
        String[] routing = {"error","info","warning","debug"};
        for (int i = 0; i < 20 ; i++) {
            int random = (int) (Math.random() * 4) ;
            String routingKey = routing[random];
            String message = "Hello rabbitMq -" + routingKey +" - " + i;

            channel.basicPublish(EXCHANGE_NAME,routingKey,null,message.getBytes("UTF-8"));
        }

        channel.close();
        connection.close();


    }
}
